
#include <windows.h>
#include <tchar.h>
#include "GetSystemSettings.h"

void RemoveAllFromDirectory(TCHAR* dirName)
{
	HANDLE hFindFile;
	WIN32_FIND_DATA data;
	TCHAR name[MAX_PATH];

    _tcscpy(name, dirName);
	_tcscat(name, TEXT("\\*.*"));

	hFindFile = FindFirstFile(name,&data);

	if ( hFindFile != INVALID_HANDLE_VALUE )
	{
		do	{
		    _tcscpy(name, dirName);
			_tcscat(name, TEXT("\\"));
			_tcscat(name, data.cFileName);

			if ( data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
			{		
				if ( _tcscmp(data.cFileName, TEXT(".")) == 0 || _tcscmp(data.cFileName, TEXT("..")) == 0 )
				{
					continue;
				}

				RemoveAllFromDirectory(name);
				RemoveDirectory(name);

				continue;
			} 
			DeleteFile(name);
		} while(FindNextFile(hFindFile,&data));

		FindClose(hFindFile);
	}
}

void ClearSystemSetting()
{
	TCHAR name[MAX_PATH];
	TCHAR fullName[MAX_PATH];
	TCHAR profile[MAX_PATH];

	GetSystemHD(name);
	GetProfileDir(profile);

	_tcscpy(fullName, TEXT("\\"));
	_tcscat(fullName, name );

	_tcscat(fullName, TEXT("\\"));
	_tcscat(fullName, profile);
	_tcscat(fullName, TEXT(" - OLD"));

	RemoveAllFromDirectory(fullName);
	RemoveDirectory(fullName);
}

void MoveSystemSettings()
{
	TCHAR name[MAX_PATH];
	TCHAR oldName[MAX_PATH];
	TCHAR newName[MAX_PATH];
	TCHAR profile[MAX_PATH];

	GetSystemHD(name);
	GetProfileDir(profile);

	_tcscpy(oldName, TEXT("\\"));
	_tcscat(oldName, name);
	_tcscat(oldName, TEXT("\\"));
	_tcscat(oldName, profile);

	_tcscpy(newName, oldName);
	_tcscat(newName, TEXT(" - OLD"));


	MoveFile(oldName, newName);
}



